package logic

import (
	"context"
	"good/goodrpc/goodrpcclient"

	"good/api/internal/svc"
	"good/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SpeakAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSpeakAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SpeakAddLogic {
	return &SpeakAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SpeakAddLogic) SpeakAdd(req *types.SpeakAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.GoodRpc.SpeakAdd(l.ctx, &goodrpcclient.SpeakAddRequest{
		UserId: int64(req.UserId),
		Text:   req.Text,
		GoodId: int64(req.GoodId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    500,
			Code:    nil,
		}, nil
	}
	return &types.Response{
		Message: "评论成功",
		Data:    200,
		Code:    add,
	}, nil

}
